package project.newCode.materials;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import project.hulpPakket.Color3f;
import project.hulpPakket.TexCoord2f;

public class Texture extends Material {

	BufferedImage image;
	String name;
	public Texture(String filename) {
		super();
		this.name=filename;
		File file= new File(filename);
		try {
			image = ImageIO.read(file);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public Color3f getCr(TexCoord2f tex) {
		int i = image.getWidth();
		int px = (int) Math.floor((tex.x-Math.floor(tex.x))*(i-1));
		int py = (int) Math.floor((tex.y-Math.floor(tex.y))*(image.getHeight()-1));
		int rgb = image.getRGB(px, py);
		Color c = new Color(rgb);
		return new Color3f(c);
	}
	
	public Texture linearCombination( Material m2, float f1, float f2) {
		Texture m = new Texture(this.getName());
		m.setCs(Color3f.Plus(Color3f.Multiply(this.getCs(), f1),Color3f.Multiply(m2.getCs(), f2)));
		m.setPhongExp(this.getPhongExp()*f1+m2.getPhongExp()*f2);
		return m;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}


}
